package com.coin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coin.domain.Coin;
import com.coin.dto.CoinDto;
import com.coin.model.R;
import com.coin.service.CoinService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @Auther: 李 力
 * @Date: 2025/6/12
 * @Description: com.coin.controller
 * @version: 1.0
 */
@RestController
@RequestMapping("/coins")
@Api(tags = "数字货币的数据接口")
public class CoinController {

    @Autowired
    private CoinService coinService;

    /**
     * @Description: 分页条件查询数字货币
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @GetMapping
    @ApiOperation(value = "分页条件查询数字货币")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "数字货币的名称"),
            @ApiImplicitParam(name = "type", value = "数字货币类型的名称"),
            @ApiImplicitParam(name = "status", value = "数字货币类型的状态"),
            @ApiImplicitParam(name = "status", value = "数字货币类型的标题"),
            @ApiImplicitParam(name = "wallet_type", value = "数字货币钱包类型"),
            @ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "size", value = "每页显示的条数"),
    })
    public R<Page<Coin>> findByPage(
            String name, String type, Byte status,
            String title, @RequestParam(name = "wallet_type", required = false) String walletType,
            @ApiIgnore Page<Coin> page) {
        Page<Coin> coinPage = coinService.findByPage(name, type, status, title, walletType, page);
        return R.ok(coinPage);
    }

    /**
     * @Description: 禁用或启用币种
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @PostMapping("/setStatus")
    @ApiOperation(value = "禁用或启用币种")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coin", value = "coin的json数据")
    })
    public R setStatus(@RequestBody Coin coin) {
        boolean isOk = coinService.setStatus(coin);
        return isOk ? R.ok(true, "操作成功") : R.fail("操作失败");
    }

    /**
     * @Description: 查询币种的详细信息
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "查询币种的详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "币种的id")
    })
    public R<Coin> info(@PathVariable("id") Long id) {
        Coin coin = coinService.info(id);
        return R.ok(coin);
    }

    /**
     * @Description: 通过状态查询所有的币种信息
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @GetMapping("/all")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "币种当前的状态")
    })
    @ApiOperation(value = "通过状态查询所有的币种信息")
    public R<List<Coin>> getCoinAll(Byte status) {
        List<Coin> coins = coinService.getCoinsByStatus(status);
        return R.ok(coins);
    }

    /**
     * @Description: 修改币种的信息
     * @Author: 李 力
     * @Date: 2025/6/12
     * @Param:
     * @return: R
     */
    @PutMapping
    @ApiOperation(value = "修改币种的信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coin", value = "coin的json数据")
    })
    public R update(@RequestBody @Validated Coin coin) {
        boolean isOk = coinService.updateCoin(coin);
        return isOk ? R.ok(true, "修改成功") : R.fail("修改失败");
    }

    /**
     * @Description: 远程调用接口
     * @Author: 李 力
     * @Date: 2025/6/20
     * @Param:
     * @return:
     */
    @GetMapping("/list")
    public List<CoinDto> coinService(List<Long> coinIds) {
        return coinService.coinService(coinIds);
    }
}
